package org.social.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.constant.MailConstant;
import org.error.GMErrorCode;
import org.social.db.bean.PlayerMap;
import org.social.db.cache.PlayerMapCache;
import org.social.manager.GMMailManager;

import com.dal.gm_api.api.IMail;
import com.dal.gm_api.util.GMError;

/**
 * Created by fxf on 2018-1-11.
 */
public class MailServer implements IMail {

    @Override
    public boolean sendMail(int type, String title, String body, Map<Integer, Integer> item, Map bodyParam, List<Integer> playerIdList) {
        GMError.isAndTrue(GMErrorCode.PARAM_ERR, "邮件缺失类型", title == null);
        GMError.isAndTrue(GMErrorCode.PARAM_ERR, "邮件缺失标题", title == null || "".equals(title));
        GMError.isAndTrue(GMErrorCode.PARAM_ERR, "邮件缺失正文", body == null || "".equals(body));
        GMError.isAndTrue(GMErrorCode.PARAM_ERR, "邮件缺失收件人", type == MailConstant.MAIL_TYPE_PERSONAL && (playerIdList == null || playerIdList.size() == 0));
        item = item == null ? new HashMap<>() : item;
        bodyParam = bodyParam == null ? new HashMap<>() : bodyParam;
        GMMailManager.sendMail(type,title,body,item,bodyParam,playerIdList);

        return true;
    }

    public List<String> queryMail(int pid, Date startTime, Date endTime){

        PlayerMap playerMap = PlayerMapCache.me().getByPid(pid);
        GMError.isAndTrue(GMErrorCode.PARAM_ERR,"pid不正确",playerMap == null);
        GMError.isAndTrue(GMErrorCode.PARAM_ERR,"时间不正确",startTime == null || endTime == null);//开始年月日时分秒
        GMError.isAndTrue(GMErrorCode.PARAM_ERR,"时间不正确",startTime.getTime() > endTime.getTime());

        List<String> result = GMMailManager.queryMail(playerMap, startTime.getTime(),endTime.getTime());
        return result;
    }
}
